﻿using StructureMap;

namespace Cinema.IoC
{
    /// <summary>
    /// This is a wrapper class the StructureMap IoC container
    /// It initializes it and provides means for accessing object instances
    /// </summary>
    public static class IoCContainer
    {
        /// <summary>
        /// Static constructor which is executed only once in the lifecycle of the 
        /// underlying system.
        /// It is executed the first time the containing class is touched.
        /// </summary>
        static IoCContainer()
        {
            // touch the settings class, so that it runs its static constructor and initializes the 
            // StructureMap IoC container
            Settings.Poke();
        }

        /// <summary>
        /// Gets an object instance of the desired type if the StructureMap IoC container can 
        /// get an object of the kind
        /// </summary>
        /// <typeparam name="T">The type of the desired object</typeparam>
        /// <returns>An instance of the desired type</returns>
        public static T Get<T>()
        {
            return ObjectFactory.GetInstance<T>();
        }
    }
}
